Method: dateutil.rrule.rrule._iter
Calls: 886, Exceptions: 17, Paths: 88Back
Path 1: 76 calls (0.09)
datetime (1124)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 2: 51 calls (0.06)
datetime (143)
None (51)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 3: 48 calls (0.05)
datetime (140)
None (48)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 4: 40 calls (0.05)
datetime (120)
None (40)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 5: 36 calls (0.04)
datetime (108)
None (36)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 6: 33 calls (0.04)
datetime (99)
None (33)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 7: 33 calls (0.04)
datetime (99)
None (33)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 8: 32 calls (0.04)
datetime (132)
None (32)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 9: 25 calls (0.03)
datetime (75)
None (25)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 10: 24 calls (0.03)
datetime (72)
None (24)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 11: 24 calls (0.03)
datetime (72)
None (24)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 12: 24 calls (0.03)
datetime (74)
None (24)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 13: 24 calls (0.03)
datetime (72)
None (24)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 14: 19 calls (0.02)
datetime (73)
None (19)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 15: 18 calls (0.02)
datetime (54)
None (18)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 16: 18 calls (0.02)
datetime (48)
None (18)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 17: 18 calls (0.02)
datetime (54)
None (18)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 18: 15 calls (0.02)
datetime (45)
None (15)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 19: 12 calls (0.01)
datetime (48)
None (12)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 20: 12 calls (0.01)
datetime (48)
None (12)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 21: 12 calls (0.01)
datetime (36)
None (12)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 22: 12 calls (0.01)
datetime (48)
None (12)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 23: 12 calls (0.01)
datetime (48)
None (12)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 24: 9 calls (0.01)
datetime (68) None (9)
GeneratorExit (9)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 25: 9 calls (0.01)
datetime (27)
None (9)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 26: 9 calls (0.01)
datetime (27)
None (9)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 27: 9 calls (0.01)
datetime (27)
None (9)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 28: 9 calls (0.01)
datetime (27)
None (9)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 29: 9 calls (0.01)
datetime (27)
None (9)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 30: 9 calls (0.01)
datetime (27)
None (9)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 31: 6 calls (0.01)
datetime (18)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 32: 6 calls (0.01)
datetime (18)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 33: 6 calls (0.01)
datetime (18)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 34: 6 calls (0.01)
datetime (24)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 35: 6 calls (0.01)
datetime (24)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 36: 6 calls (0.01)
datetime (18)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 37: 6 calls (0.01)
datetime (18)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 38: 6 calls (0.01)
datetime (18)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 39: 6 calls (0.01)
datetime (24)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 40: 6 calls (0.01)
datetime (24)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 41: 6 calls (0.01)
datetime (18)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 42: 6 calls (0.01)
datetime (18)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 43: 6 calls (0.01)
datetime (18)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 44: 6 calls (0.01)
datetime (18)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 45: 6 calls (0.01)
datetime (24)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 46: 6 calls (0.01)
datetime (24)
None (6)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 47: 5 calls (0.01)
datetime (15)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 48: 4 calls (0.0)
datetime (10)
None (4)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 49: 4 calls (0.0)
FakeDatetime (12)
None (4)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 50: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 51: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 52: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 53: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 54: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 55: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 56: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 57: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 58: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 59: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 60: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 61: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 62: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 63: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 64: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 65: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 66: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 67: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 68: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 69: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 70: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 71: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 72: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 73: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 74: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 75: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 76: 3 calls (0.0)
datetime (9)
None (3)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 77: 2 calls (0.0)
datetime (4) None (2)
GeneratorExit (2)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 78: 2 calls (0.0)
datetime (8) None (2)
GeneratorExit (2)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 79: 2 calls (0.0)
datetime (4)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 80: 1 calls (0.0)
None (1)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 81: 1 calls (0.0)
datetime (1) None (1)
GeneratorExit (1)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 82: 1 calls (0.0)
None (1)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 83: 1 calls (0.0)
ValueError (1)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 84: 1 calls (0.0)
ValueError (1)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 85: 1 calls (0.0)
ValueError (1)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 86: 1 calls (0.0)
datetime (3)
None (1)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 87: 1 calls (0.0)
datetime (2)
None (1)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)
Path 88: 1 calls (0.0)
None (1)
1def _iter(self):
2 year, month, day, hour, minute, second, weekday, yearday, _ = \
3 self._dtstart.timetuple()
4
5 # Some local variables to speed things up a bit
6 freq = self._freq
7 interval = self._interval
8 wkst = self._wkst
9 until = self._until
10 bymonth = self._bymonth
11 byweekno = self._byweekno
12 byyearday = self._byyearday
13 byweekday = self._byweekday
14 byeaster = self._byeaster
15 bymonthday = self._bymonthday
16 bynmonthday = self._bynmonthday
17 bysetpos = self._bysetpos
18 byhour = self._byhour
19 byminute = self._byminute
20 bysecond = self._bysecond
21
22 ii = _iterinfo(self)
23 ii.rebuild(year, month)
24
25 getdayset = {YEARLY: ii.ydayset,
26 MONTHLY: ii.mdayset,
27 WEEKLY: ii.wdayset,
28 DAILY: ii.ddayset,
29 HOURLY: ii.ddayset,
30 MINUTELY: ii.ddayset,
31 SECONDLY: ii.ddayset}[freq]
32
33 if freq < HOURLY:
34 timeset = self._timeset
35 else:
36 gettimeset = {HOURLY: ii.htimeset,
37 MINUTELY: ii.mtimeset,
38 SECONDLY: ii.stimeset}[freq]
39 if ((freq >= HOURLY and
40 self._byhour and hour not in self._byhour) or
41 (freq >= MINUTELY and
42 self._byminute and minute not in self._byminute) or
43 (freq >= SECONDLY and
44 self._bysecond and second not in self._bysecond)):
45 timeset = ()
46 else:
47 timeset = gettimeset(hour, minute, second)
48
49 total = 0
50 count = self._count
51 while True:
52 # Get dayset with the right frequency
53 dayset, start, end = getdayset(year, month, day)
54
55 # Do the "hard" work ;-)
56 filtered = False
57 for i in dayset[start:end]:
58 if ((bymonth and ii.mmask[i] not in bymonth) or
59 (byweekno and not ii.wnomask[i]) or
60 (byweekday and ii.wdaymask[i] not in byweekday) or
61 (ii.nwdaymask and not ii.nwdaymask[i]) or
62 (byeaster and not ii.eastermask[i]) or
63 ((bymonthday or bynmonthday) and
64 ii.mdaymask[i] not in bymonthday and
65 ii.nmdaymask[i] not in bynmonthday) or
66 (byyearday and
67 ((i < ii.yearlen and i+1 not in byyearday and
68 -ii.yearlen+i not in byyearday) or
69 (i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
70 -ii.nextyearlen+i-ii.yearlen not in byyearday)))):
71 dayset[i] = None
72 filtered = True
73
74 # Output results
75 if bysetpos and timeset:
76 poslist = []
77 for pos in bysetpos:
78 if pos < 0:
79 daypos, timepos = divmod(pos, len(timeset))
80 else:
81 daypos, timepos = divmod(pos-1, len(timeset))
82 try:
83 i = [x for x in dayset[start:end]
84 if x is not None][daypos]
85 time = timeset[timepos]
86 except IndexError:
87 pass
88 else:
89 date = datetime.date.fromordinal(ii.yearordinal+i)
90 res = datetime.datetime.combine(date, time)
91 if res not in poslist:
92 poslist.append(res)
93 poslist.sort()
94 for res in poslist:
95 if until and res > until:
96 self._len = total
97 return
98 elif res >= self._dtstart:
99 if count is not None:
100 count -= 1
101 if count < 0:
102 self._len = total
103 return
104 total += 1
105 yield res
106 else:
107 for i in dayset[start:end]:
108 if i is not None:
109 date = datetime.date.fromordinal(ii.yearordinal + i)
110 for time in timeset:
111 res = datetime.datetime.combine(date, time)
112 if until and res > until:
113 self._len = total
114 return
115 elif res >= self._dtstart:
116 if count is not None:
117 count -= 1
118 if count < 0:
119 self._len = total
120 return
121
122 total += 1
123 yield res
124
125 # Handle frequency and interval
126 fixday = False
127 if freq == YEARLY:
128 year += interval
129 if year > datetime.MAXYEAR:
130 self._len = total
131 return
132 ii.rebuild(year, month)
133 elif freq == MONTHLY:
134 month += interval
135 if month > 12:
136 div, mod = divmod(month, 12)
137 month = mod
138 year += div
139 if month == 0:
140 month = 12
141 year -= 1
142 if year > datetime.MAXYEAR:
143 self._len = total
144 return
145 ii.rebuild(year, month)
146 elif freq == WEEKLY:
147 if wkst > weekday:
148 day += -(weekday+1+(6-wkst))+self._interval*7
149 else:
150 day += -(weekday-wkst)+self._interval*7
151 weekday = wkst
152 fixday = True
153 elif freq == DAILY:
154 day += interval
155 fixday = True
156 elif freq == HOURLY:
157 if filtered:
158 # Jump to one iteration before next day
159 hour += ((23-hour)//interval)*interval
160
161 if byhour:
162 ndays, hour = self.__mod_distance(value=hour,
163 byxxx=self._byhour,
164 base=24)
165 else:
166 ndays, hour = divmod(hour+interval, 24)
167
168 if ndays:
169 day += ndays
170 fixday = True
171
172 timeset = gettimeset(hour, minute, second)
173 elif freq == MINUTELY:
174 if filtered:
175 # Jump to one iteration before next day
176 minute += ((1439-(hour*60+minute))//interval)*interval
177
178 valid = False
179 rep_rate = (24*60)
180 for j in range(rep_rate // gcd(interval, rep_rate)):
181 if byminute:
182 nhours, minute = \
183 self.__mod_distance(value=minute,
184 byxxx=self._byminute,
185 base=60)
186 else:
187 nhours, minute = divmod(minute+interval, 60)
188
189 div, hour = divmod(hour+nhours, 24)
190 if div:
191 day += div
192 fixday = True
193 filtered = False
194
195 if not byhour or hour in byhour:
196 valid = True
197 break
198
199 if not valid:
200 raise ValueError('Invalid combination of interval and ' +
201 'byhour resulting in empty rule.')
202
203 timeset = gettimeset(hour, minute, second)
204 elif freq == SECONDLY:
205 if filtered:
206 # Jump to one iteration before next day
207 second += (((86399 - (hour * 3600 + minute * 60 + second))
208 // interval) * interval)
209
210 rep_rate = (24 * 3600)
211 valid = False
212 for j in range(0, rep_rate // gcd(interval, rep_rate)):
213 if bysecond:
214 nminutes, second = \
215 self.__mod_distance(value=second,
216 byxxx=self._bysecond,
217 base=60)
218 else:
219 nminutes, second = divmod(second+interval, 60)
220
221 div, minute = divmod(minute+nminutes, 60)
222 if div:
223 hour += div
224 div, hour = divmod(hour, 24)
225 if div:
226 day += div
227 fixday = True
228
229 if ((not byhour or hour in byhour) and
230 (not byminute or minute in byminute) and
231 (not bysecond or second in bysecond)):
232 valid = True
233 break
234
235 if not valid:
236 raise ValueError('Invalid combination of interval, ' +
237 'byhour and byminute resulting in empty' +
238 ' rule.')
239
240 timeset = gettimeset(hour, minute, second)
241
242 if fixday and day > 28:
243 daysinmonth = calendar.monthrange(year, month)[1]
244 if day > daysinmonth:
245 while day > daysinmonth:
246 day -= daysinmonth
247 month += 1
248 if month == 13:
249 month = 1
250 year += 1
251 if year > datetime.MAXYEAR:
252 self._len = total
253 return
254 daysinmonth = calendar.monthrange(year, month)[1]
255 ii.rebuild(year, month)